from tkinter import Tk, Button, Label, W
from functools import partial
from gui.InputGui import InputGui
from gui.OutputGui import OutputGui
from gui.MappingGui import MappingGui
from gui.SettingGui import SettingGui


class MenuGui():
	def __init__(self, listener):
		self.root = Tk()

		self.listener = listener
		self.listener.set_gui(self)

		self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
		self.root.grid()
		self.root.minsize(200, 100)
		self.root.title('His')

		self.input = InputGui(self, self.root, listener)
		self.input.grid(row=1, column=0, columnspan=4, sticky=W)
		self.input.grid_remove()

		self.output = OutputGui(self.root, listener)
		self.output.grid(row=1, column=0, columnspan=4, sticky=W)
		self.output.grid_remove()

		self.mapping = MappingGui(self.root, listener)
		self.mapping.grid(row=1, column=0, columnspan=4, sticky=W)
		self.mapping.grid_remove()

		self.setting = SettingGui(self.root, listener)
		self.setting.grid(row=1, column=0, columnspan=4, sticky=W)
		self.setting.grid_remove()

		self.input.grid()
		self.active = self.input

		input_button = Button(self.root)
		input_button['text'] = 'Input'
		input_button['command'] = partial(self.show, self.input)
		input_button.grid(row=0, column=0)

		mapping_button = Button(self.root)
		mapping_button['text'] = 'Mapping'
		mapping_button['command'] = partial(self.show, self.mapping)
		mapping_button.grid(row=0, column=1)

		output_button = Button(self.root)
		output_button['text'] = 'Output'
		output_button['command'] = partial(self.show, self.output)
		output_button.grid(row=0, column=2)

		setting_button = Button(self.root)
		setting_button['text'] = 'Setting'
		setting_button['command'] = partial(self.show, self.setting)
		setting_button.grid(row=0, column=3)

		self.status_label = Label(self.root)
		self.status_label['text'] = 'set up configurations'
		self.status_label['pady'] = 5
		self.status_label.grid(row=2, column=0, columnspan=4)

		self.root.mainloop()

	def on_closing(self):
		self.listener.on_closing()
		self.root.destroy()

	def show(self, new):
		if self.active != new:
			self.active.grid_remove()
			self.active = new
			self.active.grid()

	def set_status(self, new_status):
		self.status_label['text'] = new_status
